﻿<%@ Page Language="C#" MasterPageFile="~/BootstrapASP.Master" AutoEventWireup="true"
    CodeBehind="Index.aspx.cs" Inherits="blog.Index" Title="Index" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script src="INC/jquery-1.11.1.js"></script>
    <script src="INC/jquery.extend.js"></script>

    <script type="text/javascript">

        count = 1
        maxnum = 1;
        postcount = 1;
      

        $(document).ready(function () {
            count = Index.getminnum().value;
            maxnum = Index.getmaxnum().value;
            getpostlist()
        })

        function appendsingel(i) {
            var checkid = Index.checkpostid(i).value;
            if (checkid == "false") {
                //alert(checkid);
                count++;
                appendsingel(count);
            }
            var paradiv = $("#postlist")

            var childdiv = $("<div></div>");
            childdiv.loadUserControl(i.toString(), null, "getlist");
            childdiv.attr('id', 'postlist' + i);
            childdiv.appendTo(paradiv);
        }

        function deletepost(obj) {
            // alert(obj.id);
            var postid = (obj.id).replace("btndelete", "");
            var url = "Class/Httphendel.ashx"
            $.get("Class/HttpHandel.ashx", { id: postid, action: "delete" }, function (data) {
                //alert(data);
                var fromdel = "1";
                //getpostlist(fromdel);
                var deletediv = $("#postlist" + postid);
                deletediv.html("");
                count++;
                appendsingel(count);
            });

        }
        function submitchange(obj) {
            var postid = (obj.id).replace("submit", "");
            alert(postid);
            alert(Index.modifypost(postid).value);
        }
        function editpost(obj) {
            var postid = (obj.id).replace("btnedit", "");
            var postdiv = $("#postlist" + postid);
            //// postdiv.html("");
            // postdiv.loadUserControl(postid, null, "getedit");

            window.open("Posts/PostEdit.aspx?postid=" + postid, '_blank');
            //  postdiv.html("");

        }

        function dealpageid(pageid) {
            var paradiv = $("#postlist")
            if (pageid == '1') {
                //count = 0;
                //paradiv.html("");
                //getpostlist('0');
                var max = pageid * 5;
                var small = max - 5;

                realpost(small, max);
            }
            else {
                var max = pageid * 5;
                var small = max - 5;

                realpost(small, max);
            }
        }

        function realpost(small, max) {
            var paradiv = $("#postlist");
            paradiv.html("");
            for (var i = small; i <= max; i++) {
                var checkid = Index.checkpostid(i).value;
                if (checkid == "false") {
                    //alert(checkid);
                    max++;
                    continue;
                }

                var childdiv = $("<div></div>");
                childdiv.loadUserControl(i.toString(), null, "getlist");
                childdiv.attr('id', 'postlist' + i);
                childdiv.appendTo(paradiv);
            }
            count = max;
        }


        function getpostlist(fromdel) {
          
            smallcount = count;
            count += 5;
            if (count > maxnum) {
                count = maxnum;
            }

            var paradiv = $("#postlist")
            if (fromdel == "1") {
                count = Index.getminnum().value;
                maxnum = Index.getmaxnum().value;
                smallcount = count;
                count += 5;
                paradiv.html("");
            }
            var timespan = 0;
            var theprogress = 0;
            for (var i = smallcount; i < count; i++) {
                var checkid = Index.checkpostid(i).value;
                if (checkid == "false") {
                    //alert(checkid);
                    count++;
                    continue;
                }
                //调用进度条
                timespan++;
                dealprogress(timespan);
                var childdiv = $("<div></div>");
                childdiv.loadUserControl(i.toString(), null, "getlist");
                childdiv.attr('id', 'postlist' + i);
                childdiv.appendTo(paradiv);

            }
            changeprogress('0');
        }

        function changeprogress(i) {
            $("#aa").html(i + "% 完成");
            $("#processbar").attr("style", "width:" + i + "%");
            
        }




        //加载进度条.
        function dealprogress(timespan) {
            smallvalue = (timespan - 1) == 0 ? 0 : (timespan - 1);
            timespan = timespan * 20;
            var total = timespan;
            var breaker = 100;
            var progress = 0;
            //var turn = 100 / (total / breaker);
            var turn = 10;
            progress = progress + turn;

            var timer = setInterval(function () {
                progress = progress + turn;
                $("#aa").html(progress + "% 完成");
                $("#processbar").attr("style", "width:" + progress + "%");
                //alert(progress);
                if (progress >= total) {
                    clearInterval(timer);
                }
            }, breaker)
           
        }


        LoadPostList = function () {

            getpostlist();
        }
    </script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <%--进度条标签.--%>
    <div class="container">
        <div class="progress progress-striped">
            <div class="progress-bar progress-bar-striped active" id="processbar"
                 role="progressbar" aria-valuenow="80" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                <span id="aa">0% 完成</span>
            </div>
        </div>
    </div>

    <input type="button" id="getpostlist" value="getpostlist" onclick="LoadPostList()" />
    <div>
        <a href="Posts/WritePost.aspx">写文章</a>



        <div id="postlist"></div>
        <div id="showposts">
            <asp:Panel ID="postpanel" runat="server">
                <%--       <a href="UserControl/PostList.ascx"--%>
            </asp:Panel>
        </div>
        <div id="relatepost"></div>

    </div>

    <div>
        <input type="button" id="button1" value="第一页" onclick="dealpageid('1')" />
        <input type="button" id="button2" value="第二页" onclick="dealpageid('2')" />
        <input type="button" id="button3" value="第三页" onclick="dealpageid('3')" />
        <input type="button" id="button4" value="第四页" onclick="dealpageid('4')" />
        <input type="button" id="button5" value="第五页" onclick="dealpageid('5')" />
        <input type="button" id="button6" value="第六页" onclick="dealpageid('6')" />
    </div>

   

</asp:Content>


